//
//  CaseTableViewCell.m
//  QuickCure
//
//  Created by 胡不归是大虾 on 9/12/16.
//  Copyright © 2016 haoge. All rights reserved.
//

#import "CaseTableViewCell.h"
#import "LKCaseModel.h"
@interface CaseTableViewCell( )

@property(nonatomic,weak) UIImageView* startPoint;


@property(nonatomic,weak) UILabel* timeLabel;

@property(nonatomic,weak) UIButton* caseImageBtn;

@property(nonatomic,weak) UILabel* illnessTypeLabel;
@property(nonatomic,weak) UILabel* illnessNameLabel;

@property(nonatomic,weak) UILabel* basicTypeLable;
@property(nonatomic,weak) UILabel* basicNameLable;

@property(nonatomic,weak) UILabel* detailLabel;


@end

@implementation CaseTableViewCell
//重写构造方法,设置UI
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpLeftLineView];
        [self setUpTimeLabel];
        [self setUpCaseImageView];
        [self setUpLabels];
    }
    return self;
}
//重写setter方法
-(void)setModel:(LKCaseModel *)model
{
    _model = model;
    
    self.illnessNameLabel.text =model.illnessTypeStr ;
    
    self.basicNameLable.text = model.basicTypeStr;
    
    self.timeLabel.text = model.commitTime;
    if (model.illnessDescStr.length != 0) {
        
        self.detailLabel.text = model.illnessDescStr;
    }
 
    [self.caseImageBtn setBackgroundImage:model.caseImage forState:UIControlStateNormal];
    if (model.caseImage == nil) {
        [self.caseImageBtn remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.timeLabel.bottom).offset(10);
            make.leading.equalTo(self.timeLabel.leading);
            make.height.equalTo(70);
            make.width.equalTo(0);
        }];
    }
    else{
        [self.caseImageBtn remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.timeLabel.bottom).offset(10);
            make.leading.equalTo(self.timeLabel.leading);
            make.width.height.equalTo(70);
        }];
    }
}
//画点
-(void)setUpLeftLineView
{
    //起始原点
    UIImageView* startPoint  = [[UIImageView alloc] init];
    self.startPoint = startPoint;
    [self.contentView addSubview:startPoint];
    startPoint.image = [UIImage imageNamed:@"illness_rb_img_sel.png"];
    [startPoint makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(15);
        make.top.equalTo(self.contentView);
        make.width.height.equalTo(15);
    }];
    
}

//创建时间标签
-(void)setUpTimeLabel
{
    UILabel* timeLabel = [[UILabel alloc] init];
    self.timeLabel = timeLabel;
    [self.contentView addSubview: timeLabel];
    
    //设置约束
    [timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(5);
        make.left.equalTo(self.startPoint.right).offset(15);
    }];
    
    self.timeLabel.textColor = [UIColor lightGrayColor];
}

//创建图片
-(void)setUpCaseImageView
{
    UIButton* caseImageBtn = [[UIButton alloc] init];
    self.caseImageBtn = caseImageBtn;
    [self.contentView addSubview:caseImageBtn];
    
    //设置约束
    [caseImageBtn makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLabel.bottom).offset(10);
        make.leading.equalTo(self.timeLabel.leading);
        make.width.height.equalTo(70);
    }];
    //设置占位图
    [caseImageBtn setBackgroundImage:[UIImage imageNamed:@"compose_pic_add_highlighted"] forState:UIControlStateNormal];
}

//创建标签
-(void)setUpLabels
{
    UILabel* illnessTypeLabel = [[UILabel alloc] init];
    self.illnessTypeLabel = illnessTypeLabel;
    [self.contentView addSubview:illnessTypeLabel];
    //设置约束
    [illnessTypeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.caseImageBtn.top);
        make.left.equalTo(self.caseImageBtn.right).offset(15);
    }];
    //设置内容
    illnessTypeLabel.text = @"疾病类型:";
    
    UILabel* basicLabelType = [[UILabel alloc] init];
    self.basicTypeLable = basicLabelType;
    [self.contentView addSubview:basicLabelType];
    //设置约束
    [basicLabelType makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.illnessTypeLabel.bottom).offset(5);
        make.leading.trailing.equalTo(self.illnessTypeLabel);
        
    }];
    //设置内容
    basicLabelType.text = @"基本类型:";
    
    UILabel* detailLabel = [[UILabel alloc] init];
    self.detailLabel = detailLabel;
    [self.contentView addSubview: detailLabel];
    //设置约束
    [detailLabel makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.illnessTypeLabel.leading);
        make.bottom.equalTo(self.caseImageBtn.bottom);
    }];
    //设置内容
    detailLabel.text = @"暂没有病症描述";
    detailLabel.textColor = [UIColor lightGrayColor];
    detailLabel.font = [UIFont systemFontOfSize:14];
    
    UILabel* illnessNameLabel = [[UILabel alloc] init];
    self.illnessNameLabel = illnessNameLabel;
    [self.contentView addSubview:illnessNameLabel];
    
    //设置约束
    [illnessNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.illnessTypeLabel.right).offset(15);
        make.top.equalTo(self.illnessTypeLabel);
    }];
    //设置内容格式
    illnessNameLabel.textColor = [UIColor lightGrayColor];
    illnessNameLabel.text = @"肿瘤科";
    
    UILabel* basicNameLabel = [[UILabel alloc] init];
    self.basicNameLable = basicNameLabel;
    [self.contentView addSubview:basicNameLabel];
    self.basicNameLable.textAlignment = NSTextAlignmentLeft;
    //设置约束
    [basicNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.basicTypeLable.right).offset(15);
        make.top.equalTo(self.basicTypeLable);
        make.right.equalTo(self.contentView).offset(-15);

    }];
    //设置内容格式
    basicNameLabel.textColor = [UIColor lightGrayColor];
    basicNameLabel.text = @"基本类型1";
}
//画线
-(void)drawRect:(CGRect)rect
{
    UIBezierPath* bezierPath = [[UIBezierPath alloc] init];
    [bezierPath moveToPoint:CGPointMake(self.startPoint.center.x, CGRectGetMaxY(self.startPoint.frame))];
    [bezierPath addLineToPoint:CGPointMake(self.startPoint.center.x, CGRectGetMaxY(self.contentView.frame))];
    [[UIColor colorWithRed:0.297 green:0.824 blue:0.709 alpha:1.000] setStroke];
    [bezierPath setLineWidth:2];
    [bezierPath stroke];
}

@end
